#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <string.h>
#include <signal.h>

#define PIPE "pipe"

void sigpipe_handler(int signo){
    perror("read crush");
    exit(0);
}

int main(int, char**){
    mkfifo(PIPE, 0666);
    char buffer[10];
    int pid = fork();
    if(pid == 0){
        int fd_r = open(PIPE, O_RDONLY);
        exit(0);
        int r = read(fd_r, buffer, sizeof(buffer));
        //printf("child: %d\n", r);
    }
    else{
        signal(SIGPIPE,sigpipe_handler);
        int fd_w = open(PIPE, O_WRONLY);
        printf("input :\n");
        char s[10];
        scanf("%s", s);
        fflush(stdin);
        if((write(fd_w, s, sizeof(s))) < 0){
            perror("error");
            return 1;
        }
    }
    printf("over\n");
    return 0;
}
